<?php

include_once "Content.php";

class Content_blog extends Content{

    private $table = 'vikno_blog_content';

    protected function insert_content($array){
        $flag = $this->db->CMS_IU(
            'INSERT INTO '.$this->table.' (id_tree, content) VALUES ( :id_tree, :content )',
            $array
        );
        return $flag;
    }

    protected function update_content($array){
        return $this->db->CMS_IU(
            'UPDATE '.$this->table.' SET content=:content WHERE id_tree=:id_tree',
            $array
        );
    }

    public function set_content($data){
        $array = array(
            ':id_tree'  => $this->id_tree+0,
            ':content'  => $data
        );
        $flag = $this->get_content();
        if ($flag){
            return $this->update_content($array);
        }else{
            return $this->insert_content($array);
        }
    }

    public function get_content(){
        $sql  = 'SELECT * FROM '.$this->table.' WHERE id_tree=:id_tree';
        $vars = array(
            ':id_tree' => $this->id_tree
        );
        $f = $this->db->CMS_query($sql, $vars);
        return $f;
    }

} 